﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

[assembly: TagPrefix("wLib.Objects", "wLib")]

namespace wLib.Objects
{

    [Designer(typeof(wlibControlDesigner))]
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:WTable runat=server></{0}:WTable>")]
    public class WTable : wlibComponent     
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["Text"] = value;
            }
        }

        public WTableDesign WTableDesign
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        protected override void OnInit(EventArgs e)
        {
            //Register client references
            RegisterResources();

            BuildMe(eNumFactory.Style);
            base.OnInit(e);
        }

        protected override void OnPreRender(EventArgs e)
        {

            base.OnPreRender(e);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(BuildMe(eNumFactory.Base));
                    
            base.Render(writer);
        }

        #region wlibComponent Members

        
        protected override string BuildMe(eNumFactory factoryType)
        {
            string scenario = string.Empty;
            switch (factoryType)
            {
                case eNumFactory.Base:
                    scenario = CreateMyBase();
                    break;
                case eNumFactory.Style:
                    //CreateMyStyle();
                    break;
                case eNumFactory.Data:
                    break;
                default:
                    break;
            }
            return scenario;
        }

        protected override string CreateMyBase()
        {
            IFactory fBase = new FactoryBase();
            return fBase.CreateFactoryScenario(eNumComponent.wTable);
        }

        protected override string CreateMyStyle()
        {
            IFactory fStyle = new FactoryStyle(this);
            return fStyle.CreateFactoryScenario(eNumComponent.wTable);
        }

        protected override string CreateMyData()
        {
            IFactory fBase = new FactoryData();
            return fBase.CreateFactoryScenario(eNumComponent.wTable);
        }


        protected override void RegisterResources()
        {
            //Get the url of the Css Resource for WTable component
            string cssResourceUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(),
                              "wLib.Objects.ClientReferences.WTable.stylesheet.text-css.WTable.css");

            //Get the url of the Javascript Resource for WTable component
            string jsResourceUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(),
                              "wLib.Objects.ClientReferences.WTable.javascript.text-javascript.WTable.js");

            //Get the url of the jQuery
            string jQResourceUrl = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js";


           this.Resources= new List<cResource>();
           this.Resources.Add(new cResource(cssResourceUrl, eNumResource.Css));
           this.Resources.Add(new cResource(jQResourceUrl, eNumResource.JavaScript));
           this.Resources.Add(new cResource(jsResourceUrl, eNumResource.JavaScript));
           

            cWorkerBus.RegisterFor(eNumComponent.wTable, this);
        }
        #endregion
    }
}